﻿using System;
using System.Collections.Generic;
using IFRS.DataAccess.DAL;
using IFRS.Models;
using IFRS.Web;
using IFRS_Global;

public partial class IFRS_WIN10_3V : PageBase
{
    #region === Event ===

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewMenu();
            BindControl();
            BindData();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }
    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN10_1S.aspx");
    }

    #endregion

    #region === Method ===

    private void ViewMenu()
    {
        MenuTitleBar = Resources.ifrsMenu.WIN10_3V;
    }
    private void BindControl()
    {
        ddlPaymentConditionID.SetData(DDL_TYPE.PaymentCondition, string.Empty, false, true);
        ddlContractLoanTypeID.SetData(DDL_TYPE.ContractLoanType, "", false, true);

        txtStatus.Text = Resources.ifrsField.CREATE;
        SetControlReadOnly(form_control);
    }
    private void BindData()
    {
        if (Convert.ToString(Request.QueryString["id"]) != string.Empty)
        {
            var id = Convert.ToInt32(Request.QueryString["id"]);
            var dt = new SPR_DISCOUNTLOAN().SEARCH_BYID(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                var list = new List<DiscountLoan>();
                ConvertHelper.ConvertDataTableToObject(dt, list);

                txtTransactionDate.Text = list[0].TransactionDate.DateToString();
                txtAccountNo.Text = list[0].AccountNo;

                txtGLAccountCode.Text = list[0].GLAccount;

                hddCostCenter.Value = list[0].CostCenter;
                txtCostCenter.Text = list[0].COST_CENTER_NM;

                txtContractStartDate.Text = list[0].ContractStartDate.DateToString();
                txtContractEndDate.Text = list[0].ContractEndDate.DateToString();
                ddlPaymentConditionID.SelectedValue = Convert.ToString(list[0].PaymentConditionID);
                txtCurrencyCode.Text = list[0].CurrencyCode;
                txtPreReceivedInterest.Text = Convert.ToString(list[0].PreReceivedInterest);
                txtLoanAmount.Text = Convert.ToString(list[0].LoanAmount);

                hddCustomerID.Value = Convert.ToString(list[0].CustomerID);
                txtCustomerID.Text = list[0].CustomerCode;

                ddlContractLoanTypeID.SelectedValue = Convert.ToString(list[0].ContractLoanTypeID);

                hddLoanObjectiveID.Value = list[0].LoanObjectiveID;
                txtLoanObjectiveID.Text = list[0].CBT_DESC_LEV1;

                txtMisPaymentDate.Text = list[0].MisPaymentDate.DateToString();

                txtApprovedAmount.Text = Convert.ToString(list[0].ApprovedAmount);
                txtReservedAmount.Text = Convert.ToString(list[0].ReservedAmount);
                txtCollateralAmount.Text = Convert.ToString(list[0].CollateralAmount);

                chkDebtAdjustFlag.Checked = !string.IsNullOrEmpty(list[0].DebtAdjustFlag) &&
                                            list[0].DebtAdjustFlag.Trim() == "Y";

                txtStatus.Text = list[0].IsConfirmed == true ? Resources.ifrsField.CONFIRM : Resources.ifrsField.CREATE;
            }
        }
    }

    #endregion
}